 <template>
   <el-card shadow="always" class="box-card">
      <div class="card-name">
        <div class="name width2">操作日志</div>
      </div>
      <div class="content-con">
        <el-form :model="form" ref="form" size="medium" label-width="80px" class="flex-s">
          <el-form-item label="日期:">
            <el-date-picker
              v-model="form.time"
              type="daterange"
              range-separator="——"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="用户:" prop="user_name">
            <el-select v-model="form.user_name" filterable clearable style="width: 100%;">
              <el-option
                v-for="item in userList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item><el-button class="save" @click="search">查 询</el-button></el-form-item>
        </el-form>
        <div class="bank-form">
          <div class="form-item">
            <el-table
              :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
              class="table"
              stripe border
              :header-cell-style="{background:'#f3f3f3',textAlign: 'center'}"
              :cell-style="{ textAlign: 'center' }">
              <el-table-column prop="datetime" label="日期" width="180">
              </el-table-column>
              <el-table-column prop="user_name" label="用户名" width="160">
              </el-table-column>
              <el-table-column prop="real_name" label="真实姓名" width="160">
              </el-table-column>
              <el-table-column prop="log" label="日志">
              </el-table-column>
            </el-table>
          </div>
          <!-- 分页-页码 -->
          <div class="page">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[5, 10, 15, 20]"
              :page-size="pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="tableData.length">
            </el-pagination>
          </div>
        </div>
      </div>
   </el-card>

 </template>
<script>

export default {
  data () {
    return {
      currentPage: 1, //当前页码
      pagesize: 5,    //每页的数据条数
      //tableData: [], //表格数据
      tableData: [
        {
          datetime: '2021-03-24 19:37:56',
          user_name: 'admin',
          real_name: '米辰科技',
          log: '登陆成功 用户名：admin'
        },
        {
          datetime: '2021-03-24 16:56:08',
          user_name: 'admin',
          real_name: '米辰科技',
          log: '修改购货单 单据编号：CG202103031254512'
        }
      ],
      form: {
        time: '',
        user_name: '0'
      },
      userList: [
        {value: '0',label: '所有用户'},
        {value: '1',label: '张三'},
        {value: '2',label: '李四'}
      ]
    }
  },

  methods: {
    //搜索
    search() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          console.log(this.form)
          this.$message.success('成功!');
        } else {
          console.log('error submit!!');
          this.$message.error('失败!');
          return false;
        }
      });
    },

    //每页条数改变时触发事件,选择一页显示多少行
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPage = 1;
      this.pagesize = val;
    },
    // 当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    }
  }
}
</script>
<style lang="scss">

</style>
